<?php
	//created by mamat, July 14, 2007
	//edited by mamat, 
	//class Page have function to handle page on mamat blog
	
	class Page {
		//this method return that data
		function getPage($pageDetailId) {
			$mysql = new Mysql();
			$mysql->connect();
			$query = "select pageDetailId,pageDate,pageTitle,pageDescribtion,pageId,userId from pagedetail where pageDetailId = $pageDetailId";
			if($mysql->execute($query)) {
				return $mysql->getDataSet();
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		}
		
		//this method return data for kind of page
		function getSubPage($pageId){
			$mysql = new Mysql();
			$mysql->connect();
			$query = "select pageDetailId,pageDate,pageTitle,pageDescribtion,pageId,userId from pagedetail where pageStatus = 1 and pageId = $pageId order by pageDetailId desc ";
			if($mysql->execute($query)) {
				return $mysql->getDataSet();
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		}
		
		function getPageTitle($pageId){
			$mysql = new Mysql();
			$mysql->connect();
			$query = "select pageDetailId,pageDate,pageTitle,pageId,userId from pagedetail where pageStatus = 1 and pageId = $pageId order by pageDetailId desc ";
			if($mysql->execute($query)) {
				return $mysql->getDataSet();
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		}
		
		function getMainPage(){
			$mysql = new Mysql();
			$mysql->connect();
			$query = "select pageDetailId,pageDate,pageTitle,pageDescribtion,pageId,userId from pagedetail where pageStatus = 1 order by pageDetailId desc limit 0,10";
			if($mysql->execute($query)) {
				return $mysql->getDataSet();
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		}
		
		function getAllMainPage(){
			$mysql = new Mysql();
			$mysql->connect();
			$query = "select pageDetailId,pageDate,pageTitle,pageDescribtion,pageId,userId from pagedetail where pageStatus = 1 order by pageDetailId desc";
			if($mysql->execute($query)) {
				return $mysql->getDataSet();
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		}
		
		//get the page author
		function getPageAuthor($userId) {
			$mysql = new Mysql();
			$mysql->connect();
			$query = "select userName from user where userId = $userId";
			if($mysql->execute($query)) {
				$author = $mysql->getDataSet();
				return $author[0][0];
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		}
		
		//this method gets page grouped
		function getPageGroup() {
			
			$mysql = new Mysql();
			$mysql->connect();
			$query = "select * from page order by pageid";
			if($mysql->execute($query)) {
				return $mysql->getDataSet();
			} else {
				return false;
			}
				
			$mysql->closeConnection();
			
		}
		
		//this method for ger row page
		function getPageNumsRow($pageId) {
			$mysql = new Mysql();
			$mysql->connect();
			if($mysql->execute("select count(pageId) from pagedetail where pageId = $pageId group by pageid")) {
				$countPage = $mysql->getDataSet();
				return $countPage[0][0];
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		}
		
		//this method gets page data for more detail use query
		function getPageDetail($query) {
			$mysql = new Mysql();
			$mysql->connect();
			if($mysql->execute($query)) {
				return $mysql->getDataSet();
			} else {
				return false;
			}
				
			$mysql->closeConnection();
		
		}
		
		//this method for edit the page
		function editPage($pageId) {
		
			return $statusEdit;
		}
		
		//this method for delete the page
		function deletePage($pageId) {
		
			return $statusDelete;
		}
		
		//this method for add the page
		function addPageDetail($pageDetailTitle, $pageDetailDesc,$userId,$pageStatus,$pageId) {
			$mysql = new Mysql();
			$mysql->connect();
			
			$query = "insert into pagedetail (pageDate, pageTitle,pageDescribtion, userId, pageStatus, pageId) values(NOW(),'$pageDetailTitle','$pageDetailDesc',$userId,$pageStatus,$pageId)";
			
			if($mysql->execute($query)) {
				return $mysql->getDataSet();
			} else {
				return false;
			}
				
			$mysql->closeConnection();
			
		}
		
		//
		function parseStr($string,$long) {
			$banding = $banding;
			$str = explode(" ",$string);
			$finalStr = "";
			for ($i = 0; $i < $long; $i++) {
				$finalStr .= $str[$i]. " ";
			}
			return $finalStr;
		}
		
		function pageFilter($string){
			
		}
	
	}

?>